<?php
class Article_model extends CI_Model {
	public $table_name="article";

    public function count_all(){
       return $this->db->count_all_results($this->table_name);
        
    }
    public function get_entries(){
        $query = $this->db->order_by('id', 'DESC')->limit(10,0)->get($this->table_name);
        return $query->result();
    }

    public function get_by_page($page,$page_size){
        $offset = ($page-1)*$page_size;
        $query = $this->db->order_by('id', 'DESC')->limit($page_size,$offset)->get($this->table_name);
        return $query->result();
    }

    public function get_one($id){
        $query = $this->db->where('id',$id)->get($this->table_name);
        return $query->row();
    }

    public function get_by_cata_id($cata_id){
        $query = $this->db->where('catalog_id',$cata_id)->get($this->table_name);
        return $query->result();
    }

    public function view_once($id){
        $this->db->query("update $this->table_name set `view`=view+1 where id=$id");
    }
    public function add_one($data){
        $data['create_time'] = time();
       $this->db->insert($this->table_name, $data);
    }
    public function edit_one($id,$data){
        $data['create_time'] = time();
        $this->db->where('id', $id)->update($this->table_name, $data);
    }
     public function del_one($id){
      $this->db->delete($this->table_name, array('id' => $id));
    }
     public function recommend_one($id,$recommend){
        $this->db->where('id',$id)->update($this->table_name,array('recommend'=> $recommend));
    }
}